<template>
  <view class="content">
    <view class="custom-page"></view>
    <view class="indexView rflex flex_y_end flex_x_end">
      <image src="https://public-yz.oss-cn-nanjing.aliyuncs.com/c0920a3e34eaa2d5cb075adb0165e9d58d731bb1565e3f2a3106d122cef1eb4e.png"></image>
    </view>
    <div class="flex_h_10"></div>
    <view class="content_content flex_p">
      <view class="content_main flex_p">
        <view class="loginView rflex ">
          <view class="flex_1 rflex">
            <view class="flex_3 cflex flex_x_center">
              <view class="hello">Hi  {{form.name}}</view>
              <view class="flex_h_2"></view>
              <view class="join">欢迎加入凯德斯大家庭</view>
            </view>
            <view class="flex_2 rflex flex_y_center flex_x_end" v-if="showBtn">
              <uv-button type="primary"  text="登入/注册" color="#2D4C98" shape="circle" @click="handleToLogin"></uv-button>
            </view>
            <!--<view class="flex_2 rflex flex_y_center flex_x_end" v-if="showBtn">
              <uv-button type="primary"  text="登入/注册" color="#2D4C98" shape="circle" open-type="getPhoneNumber" @getphonenumber="getphonenumber"></uv-button>
            </view>-->
          </view>
        </view>
        <view class="noticeView rflex flex_y_center">
          <!--<<i class="iconfont icon-lingdang"></i>
          <view class="flex_w_3"></view>
          view> 新订单消息，请查看.....</view>-->
        </view>
        <div class="choose_view">
          <view class="two_big rflex">
            <view class="flex_1 cflex flex_y_center flex_x_center">
              <view class="flex_1 cflex flex_y_center flex_x_center" @click="handleToInquiry">
                <view class="title">产品</view>
                <view class="flex_h_5"></view>
                <div class="sub_title">切割·折弯·焊接</div>
                <view class="flex_h_10"></view>
                <image src="https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/05/25/67253211781a4a8b86778bd95a04dfcb.png" style=" width: 50px;height: 50px;"></image>
              </view>
            </view>
            <div class="flex_w_10 rflex flex_x_center flex_y_center">
              <div class="line_w"></div>
            </div>
            <view class="flex_1 cflex flex_y_center flex_x_center" @click="handleToMyself">
              <view class="title">{{xunOrBao}}</view>
              <view class="flex_h_5"></view>
              <div class="sub_title">{{xunOrBao}}·派件·成交</div>
              <view class="flex_h_10"></view>
              <image src="https://public-yz.oss-cn-nanjing.aliyuncs.com/c713fd5632ff185e4e953dde20dde6e73f433687319fa6b7dbac1dbb6a0515a9.png"  style=" width: 50px;height: 50px;"></image>
            </view>
          </view>
          <view class="flex_h_10"></view>
          <view class="scroll-view">
            <uv-scroll-list>
              <view class="scroll_box cflex flex_y_center flex_x_center" v-for="(item,index) in scrollList" :key="index" @click="toOtherPages(item)">
                <image :src="item.image" style="height: 60px;width: 55px"></image>
                <view class="flex_h_10"></view>
                <view class="txt">{{item.txt}}</view>
              </view>
            </uv-scroll-list>
          </view>
        </div>
      </view>
      <div class="flex_h_15"></div>
      <div class="last_view">
        <div class="last_box"></div>
      </div>
    </view>
    <uv-popup ref="popup">
      <view class="erCodeBox" v-if="userId && userIdStr">
        <uv-qrcode size="220" :duration="0" :value="userIdStr"></uv-qrcode>
      </view>
    </uv-popup>
  </view>
</template>

<script>
  import WxLoginApi from "@/api/wxLogin/wxLogin";
  import {removeToken, removeUserInfoId, setToken, setUserInfoId} from "@/utils/auth";
  import UserInfoApi from "@/api/system/userInfo";

  export default {
    onShareAppMessage() {
      return {
        title: '欢迎加入凯德斯大家庭',
        path: 'pages/index',
      };
    },
    data() {
      return {
        userIdStr: null,
        userId: null,
        form: {},
        xunOrBao: '询价',
        showBtn: true,
        scrollList: [{
          image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/adce6d82844e4807a04fe369125e01ac.png',
          txt:'我的询价'
        },{
          image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/9cab26f985fd4ac89eb4c62541d17955.png',
          txt:'我的订单'
        },
          {
            image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/c31873ded7004d51a07a052a55b117cf.png',
            txt:'调查表'
          },{
            image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/3144aff82aca47b29a6ebd1a2e671680.png',
            txt:'二维码'
          }]
      }
    },
    onShow() {
      this.fistLogin();
    },
    methods: {
      fistLogin() {
        const that = this;
        removeToken()
        removeUserInfoId()
        uni.login({
          provider: 'weixin',
          success: (res) => {
            const data = {
              phoneCode: '',
              code: res.code,
              type: 2
            }
            WxLoginApi.wxLogin(data).then(res => {
              setToken(res?.data?.token);
              setUserInfoId(res?.data?.id)
              that.userId = res?.data?.id;
              if (res?.data) {
                that.showBtn = false;
                that.form  = res?.data;
                this.form.type = res?.data?.type.split(',')
                if (this.form.type.indexOf('2') == -1) {
                  that.scrollList = [{
                    image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/adce6d82844e4807a04fe369125e01ac.png',
                    txt:'我的询价'
                  },
                    {
                      image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/c31873ded7004d51a07a052a55b117cf.png',
                      txt:'调查表'
                    },{
                      image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/3144aff82aca47b29a6ebd1a2e671680.png',
                      txt:'二维码'
                    }]
                }else {
                  that.scrollList = [{
                    image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/adce6d82844e4807a04fe369125e01ac.png',
                    txt:'我的询价'
                  },{
                    image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/9cab26f985fd4ac89eb4c62541d17955.png',
                    txt:'我的订单'
                  },
                    {
                      image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/c31873ded7004d51a07a052a55b117cf.png',
                      txt:'调查表'
                    },{
                      image: 'https://public-yz.oss-cn-nanjing.aliyuncs.com/2025/08/19/3144aff82aca47b29a6ebd1a2e671680.png',
                      txt:'二维码'
                    }]
                }
              }
            });
          }
        })
      },

      handleToLogin() {
        uni.navigateTo({
          url: '/page_login/login?showFlag=canShow'
        })
      },

      // getphonenumber(e) {
      //   const that = this;
      //   if (e.errMsg == 'getPhoneNumber:ok') {
      //     uni.login({
      //       provider: 'weixin',
      //       success: (res) => {
      //         const data = {
      //           phoneCode: e.code,
      //           code: res.code,
      //           type: 2
      //         }
      //         WxLoginApi.wxLogin(data).then(res => {
      //           setToken(res?.data?.token);
      //           setUserInfoId(res?.data?.id)
      //           that.showBtn = false;
      //           that.form  = res?.data;
      //           // if (res?.data?.type == 2) {
      //           //   that.xunOrBao = '报价';
      //           // }
      //         });
      //       }
      //     })
      //   }
      // },
      handleToInquiry() {
        uni.navigateTo({
          url: '/page_product/index'
        })

      },
      handleToMyself() {
        uni.navigateTo( {
          url: '/page_consultation/custom'
        })
      },
      toOtherPages(item) {
        if (item.txt === '二维码') {
          if (this.userId) {
            this.userIdStr = 'erUserId:' + this.userId;
            this.$refs.popup.open();
          }else {
            uni.showToast({
              title: '登录后才能生成个人二维码！',
              icon: 'none',
              duration: 2000
            })
          }
        }else  if (item.txt === '我的询价'){
          uni.navigateTo({
            url: '/page_consultation/list'
          });
        }else if (item.txt === '我的订单') {
          uni.navigateTo({
            url: '/page_price/list'
          })
        }else if (item.txt === '调查表'){
          uni.navigateTo({
            url: '/page_investigation/index'
          })
        }
      },
    },
  }
</script>
<style>
page{
  background: #f5f5f5;
}
</style>
<style lang="scss" scoped>
.content{
  .custom-page{
    height: 130px;
    width: 100%;
    background: url("https://public-yz.oss-cn-nanjing.aliyuncs.com/58abffe597d093548a741e9c87476a3fbac450e45b199ff064c0b2c080801ad9.png") no-repeat;
    background-size: 100% 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
  }
  .indexView{
    margin-top: 80px;
    height: 220px;
    background: url("https://public-yz.oss-cn-nanjing.aliyuncs.com/7f08545fdc070ea3e0ce713f344d83df290af99b41613b7d146988d5215117bb.png") no-repeat;
    background-size: 100% 100%;
    image{
      width: 100px;
      margin-right: 30rpx;
      height: 40px;
    }
  }
  .content_content{
    .content_main{
      background: #fff;
      border-radius: 12px;
      .loginView{
        height: 55px;
        .hello{
          font-size: 32rpx;
          font-weight: bolder;
          color: #333;
        }
        .join{
          color: #5A5A5A;
          font-size: 25rpx;
        }
      }
      .noticeView{
        height: 45px;
        color: #FF0000;
      }
      .choose_view{
        background: url("https://public-yz.oss-cn-nanjing.aliyuncs.com/9834eb9fabcdcb44cb0caa3462999c970b7c2ccfe590895b4b30ac1d184bb2ec.png") no-repeat;
        background-size: 100% 100%;
        .line_w{
          width: 1px;
          height: 80px;
          border-right: 1px solid #E4E4E5
        }
        .two_big{
          height: 130px;
          image{
            width: 50px;
            height: 50px;
          }
          .title{
            font-weight: bolder;
            font-size: 35rpx;
            color: #333;
          }
          .sub_title{
            font-size: 25rpx;
            color: #5A5A5A;
          }
        }
        .scroll_box{
          width: 30vw;
        }
      }
    }
  }
  .last_box{
    height: 130px;
    background: url("https://public-yz.oss-cn-nanjing.aliyuncs.com/004ad2ece1989126f209e11af3870fb97343fe92f056bfcf86e4541f83dc7d6f.png") no-repeat;
    background-size: 100% 100%;
  }
  .er_main{
    width: 300px;
    height: 300px;
  }
}

::v-deep .uv-popup__content{
  background-color: transparent !important;
}


.erCodeBox{
  background: #fff;
  padding: 16px;
  border-radius: 15px;
}
</style>
